<template>
  <div>
    <TopFilter ref="formpanel1" :list="formList1" labelWidth="100" :isSubmitBtn="true" :collapse="false" @filterChange="formchangeFun" />
    <!-- <div style="text-align: center;">
      <el-button @click="FormPanelSeacher" type="primary">搜 索</el-button>
      <el-button @click="FormPanelreset">重置</el-button>
    </div>-->
    <div>
      <FilterTable
        ref="basetable"
        columnsRef="partInventoryManagerPartInformationAddPart"
        :columns="columns"
        height="340"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'rows'"
        :onColumnsChange="columns => (this.columns = columns)"
        :onRowSelectChange="selectTableFun"
      ></FilterTable>
    </div>
    <div style="text-align: right;height:60px;bottom:0px;position:fixed;">
      <el-button type="primary" style="margin-top:15px;" @click="addParts">添 加</el-button>
      <el-button style="margin-top:15px;" @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryAddPart } from '@/api/part/inventoryManager/partInformation';
import { addPart } from '@/api/part/inventoryManager/partInformation';
export default {
  mixins: [dictionary],
  props: ['lossNo', 'handleType'],
  data() {
    lossNo: this.lossNo, (this.basetable = null);
    // this.basetables = null;
    return {
      formList1: this.createFrom(),
      fetchApi: queryAddPart,
      fetchParams: {
        xhrAbort: true,
        sort: '',
        order: 'asc',
        limit: '10'
      },
      columns: this.createTable(),
      tablelist: [],
      toptablelist: [],
      addlist: [],
      fromSubmitdata: {},
      replacedata: {}
    };
  },
  methods: {
    createFrom() {
      return [
        {
          type: 'INPUT',
          label: '配件代码',
          placeholder: '',
          initialValue: '',
          fieldName: 'PART_NO'
        },
        {
          type: 'INPUT',
          label: '配件名称',
          placeholder: '',
          initialValue: '',
          fieldName: 'PART_NAME'
        },
        // {
        //   type: 'INPUT',
        //   label: '拼音',
        //   placeholder: '',
        //   initialValue: '',
        //   fieldName: 'STORAGE'
        // },
        {
          type: 'SELECT',
          label: '数据来源',
          placeholder: '请选择',
          initialValue: '',
          fieldName: 'OEM_TAG',
          itemList: this.createDictList('1045')
        },
        {
          type: 'SELECT',
          label: '是否有效',
          placeholder: '请选择',
          initialValue: '81311001',
          fieldName: 'IS_FREEZE',
          itemList: [
            { text: '是', value: '81311001' },
            { text: '否', value: '81311002' }
          ]
        },
        {
          type: 'SELECT',
          label: '库存大于零',
          placeholder: '请选择',
          initialValue: '',
          fieldName: 'PART_STOCK_STATUS',
          itemList: this.createDictList('1004')
        }
      ];
    },
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          sorter: true
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          sorter: true
        },
        {
          title: '配件品牌',
          dataIndex: 'BRAND',
          sorter: true
        },
        {
          title: '适用车型',
          dataIndex: 'PART_VEHICLE_MODEL',
          sorter: true
        },
        {
          title: '数据来源',
          dataIndex: 'OEM_TAG',
          render: props => {
            return <span>{this.createDictText(props.row.OEM_TAG, 1045)}</span>;
          },
          sorter: true
        },
        {
          title: '是否有效',
          dataIndex: 'IS_FREEZE',
          render: props => {
            return <span>{this.createDictText(props.row.IS_FREEZE, 1004)}</span>;
          },
          sorter: true
        },
        {
          title: '配件类型',
          dataIndex: 'PART_TYPE',
          sorter: true,
          hidden: true
        }
      ];
    },

    // 重置
    FormPanelreset() {
      this.$refs.formpanel1.RESET_FORM();
    },
    // 搜索
    FormPanelSeacher() {
      this.$refs.formpanel1.SUBMIT_FORM();
    },

    // 选中事件
    selectTableFun(val) {
      this.addlist = val;
    },
    // 添加this.addlist;
    addParts() {
      let datalist = this.addlist;
      if (datalist.length <= 0) {
        this.$notify.error({ title: '提示信息', message: '请选择要添加的信息!' });
        return;
      }
      if (this.handleType == '1') {
        this.$emit('datalistOne', datalist);
      } else {
        this.$emit('datalistTwo', datalist);
      }
      // addPart(datalist);
    },
    // 添加请求
    async addPart(row) {
      let res = await addPart(row);
      if (res.resultCode == '200') {
        this.$notify.success({ title: '提示信息', message: '添加成功!' });
      }
    },
    formchangeFun(val) {
      // console.log(11111);
      this.fetchParams = Object.assign({}, this.fetchParams, val, { xhrAbort: false });
    },
    // 关闭弹窗
    closeDialog() {
      this.$emit('close');
    }
  }
};
</script>
